<?php
header("content-type:text/html; charset=utf-8");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>超市界面</title>
   <link rel="stylesheet" href='style/index.css'/>
<style>

  </style>
</head>

<script>
  window.addEventListener('load',function(){
            //获取全部div元素
           var div1=document.querySelector('.snack-content');
            var divs=div1.getElementsByTagName('div');
        //开启定时器
            var timer=setInterval(timea,100);
            
            function timea(){
                for(var i=0;i<divs.length;i++){         
                    if(divs[i].offsetLeft>=1260){
               divs[i].style.left=-240+'px';
               }
                    divs[i].style.left=divs[i].offsetLeft+2+'px';
               
                }
            }
            //鼠标经过播放区域，则暂停定时器
            div1.addEventListener('mouseover',function(){
             clearInterval(timer);
            });
            //鼠标移出播放区域，则继续播放
            div1.addEventListener('mouseout',function(){
                timer=setInterval(timea,100);
            });       
        });

function ljgm(){
  alert('已购买成功,可将商品拿出本超市');
}
  </script>
<body>
    <div class=main>
       <div class=main_top>
       <h3>欢迎来到智能超市</h3>
       <a href="sign.html" target=_blank><button>管理员注册</button></a>
       <a href="login.html" target=_blank><button>管理员登录</button></a>
       </div>

     <?php
     $serverLink=@mysql_connect("localhost","root","root") or die("连接服务器失败！程序中断");
     mysql_query("'set names 'utf-8'");
     $dbLink=@mysql_select_db("supermarket") or die("打开supermarket数据库失败！程序中断");
     $select="select * from product where producttype='饮料类' order by inputdate desc";
     $sqlsp=mysql_query($select);
     
     ?>

      <!---------饮料专区--------->
  <div class=snack > 
    <h3>饮料专区</h3>
   <div class=snack-content>
     <?php
       $db=mysql_fetch_assoc($sqlsp);
       $a=$db['picturesrc'];
 echo'<div class=snack-one><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.' width=240px height=200px /></a>
          <h4>'.$db["productname"].'</h4>  
          <p>￥'.$db['productprice'].'</p>
          <a href=index.php?spid='.$db['Id'].'><p><button onclick="ljgm()">立即购买</button></p></a>
          
      </div>';
 ?>     
  <?php
       $db=mysql_fetch_assoc($sqlsp);
       $a=$db['picturesrc'];
 echo'<div class=snack-two><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.' width=240px height=200px /></a>
          <h4>'.$db["productname"].'</h4>  
          <p>￥'.$db['productprice'].'</p>
          <a href=index.php?spid='.$db['Id'].'><p><button onclick="ljgm()">立即购买</button></p></a>
          
      </div>';
      ?>
       <?php
       $db=mysql_fetch_assoc($sqlsp);
       $a=$db['picturesrc'];
 echo'<div class=snack-three><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.' width=240px height=200px /></a>
          <h4>'.$db["productname"].'</h4>  
          <p>￥'.$db['productprice'].'</p>
          <a href=index.php?spid='.$db['Id'].'><p><button onclick="ljgm()">立即购买</button></p></a>
          
      </div>';
      ?>
     <?php
       $db=mysql_fetch_assoc($sqlsp);
       $a=$db['picturesrc'];
 echo'<div class=snack-four><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.' width=240px height=200px /></a>
          <h4>'.$db["productname"].'</h4>  
          <p>￥'.$db['productprice'].'</p>
          <a href=index.php?spid='.$db['Id'].'><p><button onclick="ljgm()">立即购买</button></p></a>
          
      </div>';
      ?>
       <?php
       $db=mysql_fetch_assoc($sqlsp);
       $a=$db['picturesrc'];
 echo'<div class=snack-five><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.' width=240px height=200px /></a>
          <h4>'.$db["productname"].'</h4>  
          <p>￥'.$db['productprice'].'</p>
          <a href=index.php?spid='.$db['Id'].'><p><button onclick="ljgm()">立即购买</button></p></a>
          
      </div>';
      ?>
      <?php
       $db=mysql_fetch_assoc($sqlsp);
       $a=$db['picturesrc'];
 echo'<div class=snack-six><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.' width=240px height=200px /></a>
          <h4>'.$db["productname"].'</h4>  
          <p>￥'.$db['productprice'].'</p>
          <a href=index.php?spid='.$db['Id'].'><p><button onclick="ljgm()">立即购买</button></p></a>
          
      </div>';
      ?>
      </div>
</div>

  <!-----宣传专区--------->
  <div class="propager">
    <div class="left-tp"><a href=""><img src="images/宣传图片1.jpg" width="640px" height="150px"></a></div>
     <div class="right-tp"><a href=""><img src="images/宣传图片2.jpg" width="640px" height="150px"></a></div>
    </div>

<!----------零食专区------------>
<?php
    $select="select * from product where producttype='零食类' order by inputdate desc";
    $sqlsp=mysql_query($select);
    $db=mysql_fetch_assoc($sqlsp);
    ?>
        <div class="casse" id="p1">
            <h3>零食专区</h3>
            <div class="casse-content">
                <div class="casse-box">
                    <div class="tp">
                    <?php
                    $db=mysql_fetch_assoc($sqlsp);
                    $a=$db['picturesrc'];
                    echo '<a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.' width=100px height=100px /></a>';
                    echo '</div>
                    <div class="nr">';
                      echo '<h4>'.$db['productname'].'</h4>';
                     echo '<a href=index.php?spid='.$db['Id'].'><p><button onclick="ljgm()">立即购买</button></p></a>';
                     echo '<p>￥'.$db['productprice'].'</p>';
                    
                    ?>   
                     
                 </div>
                    
                </div>
                <div class="casse-box">
                 <div class="tp" id="tp2">

                 <?php
                    $db=mysql_fetch_assoc($sqlsp);
                    $a=$db['picturesrc'];
                    echo '<a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.' width=100px height=100px /></a>';
                    echo '</div>
                   <div class="nr" id="nr2">';
                      echo '<h4>'.$db['productname'].'</h4>';
                      echo '<a href=index.php?spid='.$db['Id'].'><p><button onclick="ljgm()">立即购买</button></p></a>';
                     echo '<p>￥'.$db['productprice'].'</p>';
                    ?>   
              </div>
                 
             </div>
             <div class="casse-box">
                 <div class="tp" id="tp3">	
                 <?php
                    $db=mysql_fetch_assoc($sqlsp);
                    $a=$db['picturesrc'];
                    echo '<a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.' width=100px height=100px /></a>';
                    echo '</div>
                    <div class="nr" id="nr3">';
                      echo '<h4>'.$db['productname'].'</h4>';
                      echo '<a href=index.php?spid='.$db['Id'].'><p><button onclick="ljgm()">立即购买</button></p></a>';
                     echo '<p>￥'.$db['productprice'].'</p>';
                    ?>       
                 
              </div>
                 
             </div>
             <div class="casse-box">
                 <div class="tp" id="tp4">

                 <?php
                    $db=mysql_fetch_assoc($sqlsp);
                    $a=$db['picturesrc'];
                    echo '<a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.' width=100px height=100px /></a>';
                    echo '</div>
                    <div class="nr" id="nr4">';
                      echo '<h4>'.$db['productname'].'</h4>';
                      echo '<a href=index.php?spid='.$db['Id'].'><p><button onclick="ljgm()">立即购买</button></p></a>';
                     echo '<p>￥'.$db['productprice'].'</p>';
                    ?>       
              </div>
                 
             </div>
            </div>
         
            </div>
    </div>
     <!-----宣传专区--------->
    <div class="diffuser">
    <h1>---&nbsp;<span style=color:red;>❤</span>&nbsp;猜你喜欢&nbsp;---</h1>
    </div>


 <!--------酒专区------->
 <?php
    $select="select * from product where producttype='酒类' order by inputdate desc";
    $sqlsp=mysql_query($select);
    ?>
      <div class="alcool">
 <h3>酒专区</h3>
<div class=alcool-content>
  <?php
  $alcoolcount=0;
  while($db = mysql_fetch_array($sqlsp)){
    $alcoolcount++;
  if($alcoolcount == 5){
      break;
    } 
    $a=$db['picturesrc'];
       echo ' <div class=box><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.'><div class=boxx><h2>'.$db['productname'].'</h2></a>
       <p>￥'.$db['productprice'].'
       <a href=index.php?spid='.$db['Id'].'><button onclick="ljgm()">立即购买</button></a>
       </div></div>';
  }
  ?>
    </div>
</div>

 

</div> <!-----宣传专区--------->
     <div class="two">
    <div class="left-tp"><a href=""><img src="images/宣传图片5.jpg" width="640px" height="150px"></a></div>
     <div class="right-tp"><a href=""><img src="images/宣传图片6.jpg" width="640px" height="150px"></a></div>
    </div>

 <!--------日用品专区------->
 <?php
    $select="select * from product where producttype='日用品类' order by inputdate desc";
    $sqlsp=mysql_query($select);
    $db=mysql_fetch_assoc($sqlsp);
    ?>
     <div class="alcool">
     <h3>日用品专区</h3>
   
     <div class=alcool-content>
  <?php
  $alcoolcount=0;
  while($db = mysql_fetch_array($sqlsp)){
    $alcoolcount++;
  if($alcoolcount == 5){
      break;
    } 
    $a=$db['picturesrc'];
       echo ' <div class=box><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.'><div class=boxx><h2>'.$db['productname'].'</h2></a>
       <p>￥'.$db['productprice'].'
       <a href=index.php?spid='.$db['Id'].'><button onclick="ljgm()">立即购买</button></a>
       </div></div>';
  }
  ?>
    </div>
</div>


</div> <!-----宣传专区--------->
     <div class="two">
    <div class="left-tp"><a href=""><img src="images/宣传图片1.jpg" width="640px" height="150px"></a></div>
     <div class="right-tp"><a href=""><img src="images/宣传图片2.jpg" width="640px" height="150px"></a></div>
    </div>

 <!--------文具专区------->
 <?php
    $select="select * from product where producttype='文具类' order by inputdate desc";
    $sqlsp=mysql_query($select);
    $db=mysql_fetch_assoc($sqlsp);
    ?>
    <div class="alcool">
     <h3>文具专区</h3>
     
     <div class=alcool-content>
  <?php
  $alcoolcount=0;
  while($db = mysql_fetch_array($sqlsp)){
    $alcoolcount++;
  if($alcoolcount == 5){
      break;
    } 
    $a=$db['picturesrc'];
       echo ' <div class=box><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.'><div class=boxx><h2>'.$db['productname'].'</h2></a>
       <p>￥'.$db['productprice'].'
       <a href=index.php?spid='.$db['Id'].'><button onclick="ljgm()">立即购买</button></a>
       </div></div>';
  }
  ?>
    </div>
</div>


</div> <!-----宣传专区--------->
     <div class="two">
    <div class="left-tp"><a href=""><img src="images/宣传图片1.jpg" width="640px" height="150px"></a></div>
     <div class="right-tp"><a href=""><img src="images/宣传图片2.jpg" width="640px" height="150px"></a></div>
    </div>

 <!--------牛奶专区------->
 <?php
    $select="select * from product where producttype='奶类'";
    $sqlsp=mysql_query($select);
    $db=mysql_fetch_assoc($sqlsp);
    ?>
   <div class="alcool">
     <h3>牛奶专区</h3>
  
     <div class=alcool-content>
  <?php
  $alcoolcount=0;
  while($db = mysql_fetch_array($sqlsp)){
    $alcoolcount++;
  if($alcoolcount == 5){
      break;
    } 
    $a=$db['picturesrc'];
       echo ' <div class=box><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.'><div class=boxx><h2>'.$db['productname'].'</h2></a>
       <p>￥'.$db['productprice'].'
       <a href=index.php?spid='.$db['Id'].'><button onclick="ljgm()">立即购买</button></a>
       </div></div>';
  }
  ?>
    </div>
</div>

<!--------菜专区------->
<?php
    $select="select * from product where producttype='菜类' order by inputdate desc";
    $sqlsp=mysql_query($select);
    $db=mysql_fetch_assoc($sqlsp);
    ?>
    <div class="alcool">
     <h3>菜专区</h3>
  
     <div class=alcool-content>
  <?php
  $alcoolcount=0;
  while($db = mysql_fetch_array($sqlsp)){
    $alcoolcount++;
  if($alcoolcount == 5){
      break;
    } 
    $a=$db['picturesrc'];
       echo ' <div class=box><a target=_blank href="splook.php?iid='.$db['Id'].'"><img src='.$a.'><div class=boxx><h2>'.$db['productname'].'</h2></a>
       <p>￥'.$db['productprice'].'
       <a href=index.php?spid='.$db['Id'].'><button onclick="ljgm()">立即购买</button></a>
       </div></div>';
  }
  ?>

<!-----------已经购买商品，改变商品的数量------------->
<?php
if(isset($_GET['spid'])){
 $spid=$_GET['spid'];
 $countsql="select * from product where id='$spid'";
 $spsql=mysql_query($countsql);
 $db=mysql_fetch_assoc($spsql);
 $db['productcount']=$db['productcount']-1;
 $newcount=$db['productcount'];
 $updatecount="update product set productcount='$newcount' where id='$spid'";
 mysql_query($updatecount);
//销售表
 $productname=$db['productname'];
 $vendorname=$db['inputname'];
 $salemoney=$db['productprice'];
 $date=date('Y-m-d');
$salescount=$salescount+1;
$selectsql="select * from saleslist where productname='$productname'";
mysql_query($selectsql);
$insertsql="insert into saleslist(productname,vendorname,salesmoney,salescount,salesdate) values('$productname','$vendorname','$salemoney','1','$date')";
mysql_query($insertsql);
}
mysql_close($serverLink);
?>

    </div>
</div>
</body>
</html>